using Admin2025.Domain.Repository;
using Admin2025.Infrastructure.Data;
using Admin2025.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Admin2025.Infrastructure;

public static class ServiceCollectionExtenstion
{
    public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
    {
        var connectionString = configuration.GetConnectionString("sqlserver");
        // 注册DBContext
        services.AddDbContext<Admin2025DbContext>(options =>
            options.UseSqlServer(connectionString));
        // 注册仓储实现
        services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
        return services;
    }
}